package com.faithbj.device.model.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 耗材信息表
 * @author sunshaoyan
 *
 */
@Entity
@Table(name="consumables")
public class Consumable extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	//物品编号
	private String sn;
	
	//物品名称
	private String name;
	/**
	 * 耗材种类1药剂2耗材
	 */
	private Integer category;
	
	//生产日期
	private Date manufacturingDate;
	
	//型号规格
	private String standard;
	
	//计量单位
	private String unit;
	
	//保存位置
	private String position;
	
	//保存年限
	private Integer limityears;
	
	//单价
	private BigDecimal price;
	
	//产地
	private String place;
	
	//备注
	private String commonts;
	
	//入库数
	private Integer inCount;
	
	//出库数
	private Integer outCount;
	
	//库存数
	private Integer count;
	
	private Set<StockItem> stockItemSet;
	
	public Consumable() {
	}

	@Column(name="sn")
	public String getSn() {
		return sn;
	}


	public void setSn(String sn) {
		this.sn = sn;
	}

	@Column
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	@Column(name="manufacturing_date")
	public Date getManufacturingDate() {
		return manufacturingDate;
	}

	public void setManufacturingDate(Date manufacturingDate) {
		this.manufacturingDate = manufacturingDate;
	}

	@Column
	public String getStandard() {
		return standard;
	}

	public void setStandard(String standard) {
		this.standard = standard;
	}
	@Column
	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}
	@Column
	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}
	@Column(nullable=true)
	public Integer getLimityears() {
		return limityears;
	}

	public void setLimityears(Integer limityears) {
		this.limityears = limityears;
	}
	@Column
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	@Column
	public String getPlace() {
		return place;
	}

	public void setPlace(String place) {
		this.place = place;
	}
	@Column
	public String getCommonts() {
		return commonts;
	}

	public void setCommonts(String commonts) {
		this.commonts = commonts;
	}
	@Column(name="in_count")
	public Integer getInCount() {
		return inCount;
	}

	public void setInCount(Integer inCount) {
		this.inCount = inCount;
	}
	@Column(name="out_count")
	public Integer getOutCount() {
		return outCount;
	}

	public void setOutCount(Integer outCount) {
		this.outCount = outCount;
	}
	@Column
	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}
	@Transient
	public void onSave()
	{
		    if ((this.count == null) || (this.count.intValue() < 0))
		      this.count = Integer.valueOf(0);
		    if ((this.inCount == null) || (this.inCount.intValue() < 0))
			      this.inCount = Integer.valueOf(0);
		    if ((this.outCount == null) || (this.outCount.intValue() < 0))
			      this.outCount = Integer.valueOf(0);
	}

	@Transient
	public void onUpdate()
	{
		 if ((this.count == null) || (this.count.intValue() < 0))
		      this.count = Integer.valueOf(0);
		    if ((this.inCount == null) || (this.inCount.intValue() < 0))
			      this.inCount = Integer.valueOf(0);
		    if ((this.outCount == null) || (this.outCount.intValue() < 0))
			      this.outCount = Integer.valueOf(0);
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "consumable")
	public Set<StockItem> getStockItemSet() {
		return stockItemSet;
	}

	public void setStockItemSet(Set<StockItem> stockItemSet) {
		this.stockItemSet = stockItemSet;
	}
	
	@Column
	public Integer getCategory() {
		return category;
	}

	public void setCategory(Integer category) {
		this.category = category;
	}
	
	
	

}
